<?php
header('Content-type:text/html;charset=utf-8;');

//包含数据库配置
include '../../public/peizhi.php';

//包含函数
include '../../public/func.php';

//调用函数
$link = db();

//接值表单
$lk_id = $_POST['lk_id'];
$title = $_POST['title'];
$miaoshu = $_POST['miaoshu'];
$url = $_POST['url'];

//接值文件
$_FILES;

//判断用户是否上传头像
if($_FILES['pic']['error'] != 4){
	//调用上传函数
	$uname =  upload('pic','../../uploads');
	//调用缩放函数
	$newpic = suofang('../../uploads/'.basename($uname),30,30,'../../uploads/');
	//删除缩放前的原图
	if(isset($newpic)){
		unlink('../../uploads/'.basename($uname));
	}
}else{
	$newpic = $_POST['oldpic'];
}

//准备SQL语句
$sql = "update link set title='{$title}',miaoshu='{$miaoshu}',url='{$url}',pic='{$newpic}' where id='{$lk_id}'";

//执行SQL语句
if($res = mysqli_query($link,$sql)){
	echo '<script>alert("修改成功");window.location.href="show.php";</script>';
}else{
	echo '<script>alert("修改失败");window.location.href="show.php";</script>';
}

//关闭数据库连接
mysqli_close($link);

